#import <UIKit/UIKit.h>
#import "TFConnection.h"
#import "Status.h"
#import "FriendGroup.h"
#import "Remark.h"

typedef enum {
    TWITTER_REQUEST_TIMELINE,
    TWITTER_REQUEST_REPLIES,
    TWITTER_REQUEST_MESSAGES,
    TWITTER_REQUEST_SENT,
    TWITTER_REQUEST_FAVORITE,
    TWITTER_REQUEST_DESTROY_FAVORITE,
    TWITTER_REQUEST_CREATE_FRIENDSHIP,
    TWITTER_REQUEST_DESTROY_FRIENDSHIP,
    TWITTER_REQUEST_FRIENDSHIP_EXISTS,
} RequestType;

@interface TwitterClient : TFConnection
{
    RequestType request;
    id          context;
    SEL         action;
    BOOL        hasError;
    NSString*   errorMessage;
    NSString*   errorDetail;
}

@property(nonatomic, readonly) RequestType request;
@property(nonatomic, assign) id context;
@property(nonatomic, assign) BOOL hasError;
@property(nonatomic, copy) NSString* errorMessage;
@property(nonatomic, copy) NSString* errorDetail;

- (id)initWithTarget:(id)delegate action:(SEL)action;

- (void)getTimeline:(TweetType)type params:(NSDictionary*)params;

//- (void)getUserTimeline:(NSString*)screen_name params:(NSDictionary*)params;
- (void) getUserTimeline:(long long)userId params:(NSDictionary *)params;

- (void)getUser:(NSString*)screen_name;
- (void) getUserById:(sqlite_int64)userId;

- (void) getMessageConversation:(sqlite_int64)userId;
- (void)getMessage:(sqlite_int64)statusId;

- (void)post:(NSString*)tweet inReplyTo:(sqlite_int64)statusId;
- (void)post:(NSString*)tweet inReplyTo:(sqlite_int64)statusId attach:(NSDictionary*)attach;
- (void) postGroup:(NSString*)tweet group:(FriendGroup*)group;
- (void) postGroup:(NSString*)tweet group:(FriendGroup*)group attach:(NSDictionary*)attach;

- (void)send:(NSString*)text to:(NSString*)screen_name;
- (void)sendGroup:(NSString*)text group:(FriendGroup*)group;

- (void)getFriends:(NSString*)screen_name page:(int)page isFollowers:(BOOL)isFollowers;
- (void)getFriendsByUserId:(sqlite_int64)userId page:(int)page isFollowers:(BOOL)isFollowers;
- (void)getFriendsByUserId:(sqlite_int64)userId page:(int)page rows:(int)rows orderby:(int)orderby isFollowers:(BOOL)isFollowers;
+ (NSArray*) getFriendsSync:(sqlite_int64)userId page:(int)page rowsPerPage:(int)rowsPerPage;

- (void) friendship:(sqlite_int64)userId create:(BOOL)create;
- (void) existFriendship:(NSString*)screen_name;
+ (BOOL) createFriendshipSync:(sqlite3_int64)userId;
+ (BOOL) destroyFriendshipSync:(sqlite3_int64)userId;

- (void)destroy:(Tweet*)tweet;
- (void)favorites:(NSString*)screenName page:(int)page;
- (void)toggleFavorite:(Status*)status;
- (void)search:(NSString*)query;
- (void)updateLocation:(NSString*)tweet latitude:(float)latitude longitude:(float)longitude;
- (void)trends;
- (void)verify;
+ (User*) verifyAccount;
+ (User*) verifyAccount:(NSString*)username password:(NSString*)password;

+ (NSArray*) getGroups;
- (void) getUsersInGroup:(sqlite_int64)groupId;
+ (NSMutableArray*) getUserInGroupSync:(sqlite_int64)groupId;
+ (BOOL) setUserGroupsSync:(NSArray*)groupIds userId:(sqlite_int64)userId operation:(NSString*)op;

+ (BOOL) createUserGroupSync:(FriendGroup*)group;
+ (BOOL) destroyUserGroupSync:(sqlite_int64)groupId;
+ (BOOL) updateUserGroupSync:(FriendGroup*)group;

- (void) searchUser:(NSString*)screenName;

//微博
- (void) loadStatus:(long long)statusId;
- (void) retweet:(Status*)status;
- (void) retweetUsers:(long long)statusId pageNo:(NSInteger)pageNo rowsPerPage:(NSInteger)rows;
+ (BOOL) retweetSync:(Status*)status;

//评论
- (void) remarkList:(long long)statusId sinceTime:(time_t)sinceTime;
+ (Remark*) publishRemarkSync:(Remark*)remark status:(Status*)originStatus;

//数据上传
- (void) dataup:(NSArray*)records;
+ (id) dataupSync:(NSArray *)records response:(NSHTTPURLResponse**)response error:(NSError**)error;

//默默关注
- (void) getSilenceFollowings;
+ (BOOL) createSilenceFollowingSync:(sqlite3_int64)userId;
+ (BOOL) destroySilenceFollowingSync:(sqlite3_int64)userId;

//名片
- (void) getMyCards;
- (void) askCard:(long long)userId;
+ (BOOL) acceptAskCardSync:(NSString*)askId dmId:(long long)dmId cardId:(long long)cardId;
+ (BOOL) rejectAskCardSync:(NSString*)askId dmId:(long long)dmId message:(NSString*)message;

//注册
+ (BOOL) registerSync:(long long)userId name:(NSString*)name password:(NSString*)password;
+ (BOOL) activateSync:(long long)userId activateCode:(NSString*)code  screenName:(NSString*)name password:(NSString*)password;

- (void)alert;

@end
